package com.ylyq.lingoserver.rabbitmq;

import com.rabbitmq.client.Channel;
import com.ylyq.lingoserver.constants.RabbitConstant;
import com.ylyq.lingoserver.service.ILingoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * @ClassName RabbitDirectReceiver
 * @Description TODO 创建消息接收监听类
 * @Author xiaweichao
 * @Date 2020/7/17 16:09
 * @Version 1.0
 */
@Slf4j
@Component
//这一行不用mq的时候注释
//@RabbitListener(queues = RabbitConstant.LINGOQUEUE)//监听的队列名称 TestDirectQueue
public class RabbitDirectReceiver {
    @Autowired
    private ILingoService iLingoService;
    @RabbitHandler
    public void process(Map testMessage, Message message, Channel channel) {

        log.info("DirectReceiver消费者收到消息  : " + testMessage.toString());
        try {
            iLingoService.excuteLingo(testMessage);
            //确认收到message
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
